package com.cxw.healthserver.controller

import com.cxw.healthserver.constant.Constants
import com.cxw.healthserver.entity.User
import com.cxw.healthserver.resolver.CurrentUser
import com.cxw.healthserver.response.BaseResponse
import com.cxw.healthserver.service.SignInfoService
import com.fasterxml.jackson.databind.JsonNode
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.*

/**
 * @createTime 2024/6/25 22:37
 * @author 崔兴旺
 * @description
 */
@RestController
@RequestMapping("api")
class SignInfoController {

    @Autowired
    private lateinit var signInfoService: SignInfoService

    /**
     * 下载签约信息
     */
    @GetMapping("downloadSignInfo")
    fun downloadSignInfo(@CurrentUser user: User, @RequestParam idNumber: String): BaseResponse<JsonNode> {
        return BaseResponse.success(signInfoService.querySignInfo(user.username, idNumber))
    }

    /**
     * 上传签约信息
     */
    @PostMapping("uploadSignInfo", produces = [Constants.produces])
    fun uploadSignInfo(@CurrentUser user: User, @RequestBody jsonStr: String): BaseResponse<Any> {
        return signInfoService.saveSignInfo(user.username,jsonStr)
    }
}